//
//  EveryDaySelectVC.m
//  DFront
//
//  Created by lanou on 15/10/27.
//  Copyright © 2015年 xuzenghui. All rights reserved.
//

#import "EveryDaySelectVC.h"
#import "SJTableViewController.h"
#import "BookTableViewController.h"
#import "ShotTableViewController.h"
#import "PadTableViewController.h"
#import "HardWareTableViewController.h"

@interface EveryDaySelectVC ()<UIScrollViewDelegate>
@property (nonatomic, strong) UIScrollView *mainScrollView;
@property (nonatomic, strong) UIScrollView *aScrollView;
@property (nonatomic, strong) UILabel *line;
@property (nonatomic, strong) UILabel *bline;
@property (nonatomic, strong) UILabel *cline;
@property (nonatomic, strong) UILabel *dline;
@property (nonatomic, strong) UILabel *eline;

@end

@implementation EveryDaySelectVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.hidden = YES;
    self.view.backgroundColor = [UIColor whiteColor];
    [self addScrollView];
    [self addPhone];
    [self addBook];
    [self.topView addSubview:self.backBtn];
    [self.view addSubview:self.topView];
    [self addTopScrollView];
    [self addShot];
    [self addPad];
    _mainScrollView.delegate = self;
    
    HardWareTableViewController *hardVC = [[HardWareTableViewController alloc] init];
    [self addChildViewController:hardVC];
    hardVC.view.frame = CGRectMake(kScreenWidth * 4, 0, kScreenWidth, kScreenHeight - 64);
    [_mainScrollView addSubview:hardVC.view];
    
    }

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if (_mainScrollView.contentOffset.x / kScreenWidth == 0) {
        _line.backgroundColor = [UIColor whiteColor];
        _bline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _cline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _dline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _eline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    }
    else if (_mainScrollView.contentOffset.x / kScreenWidth == 1)
    {
        _line.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _bline.backgroundColor = [UIColor whiteColor];
        _cline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _dline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _eline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _aScrollView.contentOffset = CGPointMake(0, 0);
    }
    else if (_mainScrollView.contentOffset.x / kScreenWidth == 2)
    {
        _line.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _bline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _cline.backgroundColor = [UIColor whiteColor];
        _dline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _eline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    }
    else if (_mainScrollView.contentOffset.x / kScreenWidth == 3)
    {
        _line.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _bline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _cline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _dline.backgroundColor = [UIColor whiteColor];
        _eline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _aScrollView.contentOffset = CGPointMake(kScreenWidth / 2 + 68, 0);
    }
    else if (_mainScrollView.contentOffset.x / kScreenWidth == 4)
    {
        _line.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _bline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _cline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _dline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _eline.backgroundColor = [UIColor whiteColor];
    }
    
}


//添加顶部scrollView
- (void)addTopScrollView
{
    _aScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(kScreenWidth / 2 - 70, 7, kScreenWidth / 2 + 67, 36)];
    _aScrollView.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    [self.topView addSubview:_aScrollView];
    _aScrollView.showsHorizontalScrollIndicator = NO;
    _aScrollView.contentSize = CGSizeMake((kScreenWidth / 2 + 68) * 2, 0);
    UIButton *aBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    aBtn.frame = CGRectMake(0, 0, kScreenWidth / 4, 33);
    [aBtn setTitle:@"手机精选" forState:UIControlStateNormal];
    [_aScrollView addSubview:aBtn];
    [aBtn addTarget:self action:@selector(one:) forControlEvents:UIControlEventTouchUpInside];
    _line = [[UILabel alloc] initWithFrame:CGRectMake(0, 33, kScreenWidth / 4, 2)];
    _line.backgroundColor = [UIColor whiteColor];
    [_aScrollView addSubview:_line];
    UIButton *bBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    bBtn.frame = CGRectMake(100, 0, kScreenWidth / 4, 33);
    [bBtn setTitle:@"笔记本精选" forState:UIControlStateNormal];
    [_aScrollView addSubview:bBtn];
    [bBtn addTarget:self action:@selector(two:) forControlEvents:UIControlEventTouchUpInside];
    _bline = [[UILabel alloc] initWithFrame:CGRectMake(100, 33, kScreenWidth / 4, 2)];
    [_aScrollView addSubview:_bline];
    UIButton *cBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cBtn.frame = CGRectMake(200, 0, kScreenWidth / 4, 33);
    [cBtn setTitle:@"摄影精选" forState:UIControlStateNormal];
    [_aScrollView addSubview:cBtn];
    [cBtn addTarget:self action:@selector(three:) forControlEvents:UIControlEventTouchUpInside];
    _cline = [[UILabel alloc] initWithFrame:CGRectMake(200, 33, kScreenWidth / 4, 2)];
    [_aScrollView addSubview:_cline];
    UIButton *dBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    dBtn.frame = CGRectMake(300, 0, kScreenWidth / 4, 33);
    [dBtn setTitle:@"平板精选" forState:UIControlStateNormal];
    [_aScrollView addSubview:dBtn];
    [dBtn addTarget:self action:@selector(four:) forControlEvents:UIControlEventTouchUpInside];
    _dline = [[UILabel alloc] initWithFrame:CGRectMake(300, 33, kScreenWidth / 4, 2)];
    [_aScrollView addSubview:_dline];
    UIButton *eBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    eBtn.frame = CGRectMake(400, 0, kScreenWidth / 4, 33);
    [eBtn setTitle:@"硬件精选" forState:UIControlStateNormal];
    [_aScrollView addSubview:eBtn];
    [eBtn addTarget:self action:@selector(five:) forControlEvents:UIControlEventTouchUpInside];
    _eline = [[UILabel alloc] initWithFrame:CGRectMake(400, 33, kScreenWidth / 4, 2)];
    [_aScrollView addSubview:_eline];
    aBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    bBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    cBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    dBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    eBtn.titleLabel.font = [UIFont systemFontOfSize:16];

}
- (void)one:(UIButton *)sender
{
    _mainScrollView.contentOffset = CGPointMake(0, - 20);
    _line.backgroundColor = [UIColor whiteColor];
    _bline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _cline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _dline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _eline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
}
- (void)two:(UIButton *)sender
{
    _mainScrollView.contentOffset = CGPointMake(kScreenWidth, - 20);
    _line.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _bline.backgroundColor = [UIColor whiteColor];
    _cline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _dline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _eline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
}
- (void)three:(UIButton *)sender
{
    _mainScrollView.contentOffset = CGPointMake(kScreenWidth * 2, - 20);
    _line.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _bline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _cline.backgroundColor = [UIColor whiteColor];
    _dline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _eline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _aScrollView.contentOffset = CGPointMake(kScreenWidth / 2 + 68, 0);
}
- (void)four:(UIButton *)sender
{
    _mainScrollView.contentOffset = CGPointMake(kScreenWidth * 3, - 20);
    _line.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _bline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _cline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _dline.backgroundColor = [UIColor whiteColor];
    _eline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];

}
- (void)five:(UIButton *)sender
{
    _mainScrollView.contentOffset = CGPointMake(kScreenWidth * 4, - 20);
    _line.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _bline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _cline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _dline.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _eline.backgroundColor = [UIColor whiteColor];

}

//添加scrollView
- (void)addScrollView
{
    _mainScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 44, kScreenWidth, kScreenHeight - 88)];
    _mainScrollView.contentSize = CGSizeMake(kScreenWidth * 5, 0);
    _mainScrollView.pagingEnabled = YES;
    _mainScrollView.showsHorizontalScrollIndicator = NO;
    _mainScrollView.bounces = NO;
    [self.view addSubview:_mainScrollView];
}
//添加手机精选
- (void)addPhone
{
    SJTableViewController *SjVC = [[SJTableViewController alloc] init];
    [self addChildViewController:SjVC];
    SjVC.view.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - 64);
    [_mainScrollView addSubview:SjVC.view];
}
//添加笔记本精选
- (void)addBook
{
    BookTableViewController *bookVC = [[BookTableViewController alloc] init];
    [self addChildViewController:bookVC];
    bookVC.view.frame = CGRectMake(kScreenWidth, 0, kScreenWidth, kScreenHeight - 64);
    [_mainScrollView addSubview:bookVC.view];
}
//添加摄影精选
- (void)addShot
{
    ShotTableViewController *shotVC = [[ShotTableViewController alloc] init];
    [self addChildViewController:shotVC];
    shotVC.view.frame = CGRectMake(kScreenWidth * 2, 0, kScreenWidth, kScreenHeight - 64);
    [_mainScrollView addSubview:shotVC.view];
}
//添加平板控
- (void)addPad
{
    PadTableViewController *padVC = [[PadTableViewController alloc] init];
    [self addChildViewController:padVC];
    padVC.view.frame = CGRectMake(kScreenWidth * 3, 0, kScreenWidth, kScreenHeight - 64);
    [_mainScrollView addSubview:padVC.view];
}










@end
